# -*- coding: utf-8 -*-
# ㊎ Author : XMZ
# ㊍ Time : 2021/10/13 10:09
# ㊌ File : formula -> serializers.py
# ㊋ IDE :  PyCharm
# ㊏ 
import os
import sys
from rest_framework import serializers
from .models import UserProfile


class UserProfileSerializers(serializers.ModelSerializer):
    # user_code = serializers.ReadOnlyField(source='user_code.外键字段') # 处理外键关联 外外键字段只读

    # 元数据
    class Meta:
        model = UserProfile  # 声明模型类
        # exclude = ("id",) # 排除字段
        # fields = ("user_code", "username") # 序列化指定字段
        fields = "__all__"  # 序列化所有字段
        # extra_kwargs = {
        #     'first_name': {
        #         'help_text': '姓氏，字符串，1-4位',
        #         'min_length': 1,
        #         'max_length': 4,
        #         'error_messages': {
        #             'min_length': '最少1个字符',
        #             'max_length': '最多4个字符'
        #         }
        #     },
        #     'last_name': {
        #         'help_text': '姓名，字符串,2-10位'
        #     },
        #     'instrument': {
        #         'help_text': '备注，字符串，0-255位',
        #         'min_length': 0,
        #         'max_length': 255,
        #         'error_messages': {
        #             'min_length': '最少0个字符',
        #             'max_length': '最多255个字符'
        #         }
        #     },
        # }

# # 展示查询链接
# class UserProfileSerializers2(serializers.HyperlinkedModelSerializer):
#     # user_code = serializers.ReadOnlyField(source='user_code.外键字段') # 处理外键关联 外外键字段只读
#     # 元数据
#     class Meta:
#         model = UserProfile  # 声明模型类
#         # exclude = ("id",) # 排除字段
#         # 这里url是系统默认的，如果要改；在setting中设置：URL_FIELD_NAME 使全局生效
#         # fields = ("user_code", "username","url) # 序列化指定字段
#         fields = "__all__"  # 序列化所有字段
#         depth = 2  # 序列化 关联的深度
